package dapps.entity.document;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.OrderBy;

import dapps.entity.IdEntity;

/**
 * 文档分类.
 * 
 */
@Entity
@Table(name = "category")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Category extends IdEntity implements Serializable {
		
	/**
	 * 
	 */
	private static final long serialVersionUID = -1153407727194898213L;


	@Column(nullable=false,unique=true)
	private String name;

	
	private Set<Document> docs = new HashSet<Document>(0);
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "category")
	@OrderBy(clause="id desc")
    public Set<Document> getDocs() {
            return docs;
    }
	

	public void setDocs(Set<Document> docs) {
		this.docs = docs;
	}

	public String toString() {
		return this.getName();
	}

}